package shangji2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import shangji2.config.PrinterConfig;

public class PrinterTest {
    public static void main(String[] args) {
        // 使用Java配置类加载Spring上下文
        ApplicationContext context = new AnnotationConfigApplicationContext(PrinterConfig.class);

        // 或者使用XML配置文件（如果保留了XML配置）
        // ApplicationContext context = new ClassPathXmlApplicationContext("printerContext.xml");

        // 获取彩色打印机和黑白打印机实例
        Printer colorPrinter = (Printer) context.getBean("colorPrinter");
        Printer bwPrinter = (Printer) context.getBean("bwPrinter");

        // 测试彩色打印机打印
        System.out.println("\n彩色打印机测试页：");
        colorPrinter.print();

        // 测试黑白打印机打印
        System.out.println("\n黑白打印机测试页：");
        bwPrinter.print();

        // 演示切换纸张
        System.out.println("\n彩色打印机切换到B5纸张：");
        colorPrinter.setZhi(context.getBean("b5zhi", shangji2.Dao.Zhizhang.class));
        colorPrinter.print();
    }
}